package cn.db101.kaoqinserver.controller;

import cn.db101.kaoqinserver.config.ApiResult;
import cn.db101.kaoqinserver.domain.Classes;
import cn.db101.kaoqinserver.domain.User;
import cn.db101.kaoqinserver.model.request.ClassesParam;
import cn.db101.kaoqinserver.service.ClassesService;
import cn.db101.kaoqinserver.service.UserService;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("v1/kaoqin/student")
public class StudentController {

    @Autowired
    private UserService userService;

    @Autowired
    private ClassesService classesService;

    @PostMapping("classes/page")
    public ApiResult<?> page(@RequestBody ClassesParam classesParam) {

        return ApiResult.ofSuccess(userService.classesPage(classesParam));
    }

    @GetMapping("classes/list")
    public ApiResult<?> classesList() {

        return ApiResult.ofSuccess(classesService.list());
    }

    @PostMapping("classes/create")
    public ApiResult<?> classesCreate(@RequestBody Classes classes) {

        classesService.create(classes);
        return ApiResult.ofSuccess();
    }

    @PostMapping("classes/update")
    public ApiResult<?> classesUpdate(@RequestBody Classes classes) {

        classesService.update(classes);
        return ApiResult.ofSuccess();
    }

    @PostMapping("bindClass")
    public ApiResult<?> bindClass(@RequestBody User user) {

        int loginId = Integer.parseInt(StpUtil.getLoginId().toString());
        user.setId(loginId);
        userService.bindClass(user);
        return ApiResult.ofSuccess();
    }

    @PostMapping("bindFace")
    public ApiResult<?> bindFace(@RequestBody User user) {

        int loginId = Integer.parseInt(StpUtil.getLoginId().toString());
        user.setId(loginId);
        userService.bindFace(user);
        return ApiResult.ofSuccess();
    }

    @PostMapping("list")
    public ApiResult<?> list() {

        return ApiResult.ofSuccess(userService.list());
    }

}
